<?php
/**
 * Created by PhpStorm.
 * User: yangyulu
 * Date: 2020/3/10
 * Time: 下午1:21
 */
class Admin_bonusController extends Admin_baseController{
    public function listAction(){
        $page = Request::getParams('page', 1);
        $pageSize = Request::getParams('pageSize', 20);
        $name=Request::getParams("name");
        $where = $value = $url = array();
        if ($name) {
            $where[] = 'name like ?';
            $value[] = '%' . $name . '%';
            $url['name'] = $name;
        }
        $total = self::model('bonus_config')->count('id', $where, $value);
        $list = self::model('bonus_config')->limit(($page - 1) * $pageSize, $pageSize)->order('id desc')->getAll($where, $value);
        $this->assign(array(
            'page' => $page,
            'pageSize' => $pageSize,
            'name' => $name,
            'total' => $total,
            'list' => $list,
            'pageHtml' => self::instance('Pagination')->page($page)->num($pageSize)->total($total)->url(Router::getBaseUrl() . '/admin_vote/list?' . ($url ? http_build_query($url) : '') . '&page=')->rendHtml(),
        ));
        $this->display();
    }

    public function editAction(){
        $ids = Request::getParams('ids');
        $integral=Request::getParams("integral");
        if ($ids && !$info = self::model('bonus_config')->getOne('id=?', $ids)) {
            Response::showMsg('信息查询失败，请稍后重试');
        }
        if (Request::isGet()) {
            $this->assign([
                'info' => $info,
            ]);

            $this->display();
            exit;
        }

        if(empty($integral)){
            Response::ajax(NORMAL_ERROR,'请填填写积分数量');
        }
        $data["integral"]=$integral;
        if($ids){
            self::model("bonus_config")->update($data,"id=?",$ids);
            Response::ajax(200, '修改成功');
        }else{
            $data["add_time"]=date("Y-m-d H:i",time());
            self::model("bonus_config")->insert($data);
            Response::ajax(200, '添加成功');
        }
    }
}